
#!/usr/bin/python3
# coding=UTF-8
import math as m
class square(object):
    def __init__(self,a):
        self.a=a
    def perimeter(self):
        return 4 * self.a
    def area(self):
        return self.a ** 2
    def __str__(self):
        return "正方形的边长是"+str(self.a)+"。"
class rectangle(object):
    def __init__(self,a):
        self.a=a[0]
        self.b=a[1]
    def perimeter(self):
        return 2 * (self.a + self.b)
    def area(self):
        return self.a * self.b
    def __str__(self):
        return "矩形的长是"+str(self.a)+"矩形的宽是"+str(self.b)+"。"
class triangle(object):
    def __init__(self,a):
        self.a=a[0]
        self.b=a[1]
        self.c=a[2]
        self.p=(a[0]+a[1]+a[2])/2
    def perimeter(self):
        return self.a + self.b + self.c
    def area(self):
        return m.sqrt(self.p*(self.p-self.a)*(self.p-self.b)*(self.p-self.c))
    def __str__(self):
        return "三角形的A边是"+str(self.a)+"，三角形的A边是"+str(self.b)+"，三角形的A边是"+str(self.c)+"。"
def Square():
    while True:
        a=input("请输入正方形的边长：")
        try:
            a=int(a)
            if a>=0:
                break
        except:
            pass
    S=square(a)
    SA=S.area()
    SP=S.perimeter()
    print(S,"它的面积是",SA,"。它的周长是",SP,"。")
def Rectangle():
    while True:
        a=input("请输入矩形的长：")
        b=input("请输入矩形的宽：")
        try:
            a=int(a)
            b=int(b)
            if a>0 and b>0:
                break
        except:
            pass
    S=rectangle([a,b])
    SA=S.area()
    SP=S.perimeter()
    print(S,"它的面积是",SA,"。它的周长是",SP,"。")
def Triangle():
    while True:
        a=input("请输入三角形的A边：")
        b=input("请输入三角形的B边：")
        c=input("请输入三角形的C边：")
        try:
            a=int(a)
            b=int(b)
            c=int(c)
            if a>0 and b>0 and c>0 and a+b>c and a+c>b and b+c>a:
                break
        except:
            pass
    S=triangle([a,b,c])
    SA=S.area()
    SP=S.perimeter()
    print(S,"它的面积是",SA,"。它的周长是",SP,"。")
while True:
    print("将计算面积和周长，请选择一个几何形状：")
    print("1.正方形")
    print("2.矩形")
    print("3.三角形")
    print("0.退出")
    choice=input("你的选择：")
    match choice:
        case "1":
            Square()
        case "2":
            Rectangle()
        case "3":
            Triangle()
        case _:
            break
